<template>
  <el-container class="container_box">
    <el-header height="">
      <div class="img">
        <img src="../assets/logo_mobile.png" alt="" />
        <div>用户权限管理系统</div>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏导航菜单区域aside -->
      <el-aside width="180px">
        <el-col>
          <el-menu
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            :default-active="activePath"
            :collapse-transition="false"
            :collapse="isCollapse"
          >
            <el-submenu :index="nume.id + ''" v-for="nume in menuList">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ nume.name }}</span>
              </template>
              <!-- 二级菜单区域 -->
              <el-menu-item :index="'' + n.url" v-for="n in nume.menu" @click="saveNavState(''+n.url)">{{
                n.name
              }}</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-col>
      </el-aside>
      <!-- 主体区域main -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menuList: [],
      //是否折叠
      isCollapse: false,
      //被激活的链接地址
      activePath: "",
    };
  },
  created() {
    this.getMenuList();
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenuList() {
      const { data: res } = await this.$axios.get("/menu/getmenu");
      if (res.status === 400) this.$message.error(res.msg);
      this.menuList = res.res;
      console.log(res);
    },
    //保存连接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
  },
};
</script>

<style lang="less" scoped>
.container_box {
  height: 100%;
}
.el-main {
  background-color: white;
  color: #333;
}
.el-aside {
  background-color: #545c64;
  color: #333;
}
.el-header {
  background-color: gray;
  color: #333;
  display: flex;
  justify-content: space-between;
  > .el-button {
    margin: 10px;
  }
}
.img {
  display: flex;
  margin: 10px;
  padding-left: 15px;
  > div {
    display: flex;
    align-items: center;
    margin-left: 65px;
    color: white;
    font-size: 20px;
  }
}
.el-menu {
  border-right: 0px;
}
</style>